#include <iostream>

using std::cout;
using std::endl;

class A{
public:
    virtual void a(){ cout << "A::a()" << endl; }
    virtual void b(){ cout << "A::b()" << endl; }
    virtual void c(){ cout << "A::c()" << endl; }
};

class B{
public:
    virtual void a(){ cout << "B::a()" << endl; }
    virtual void b(){ cout << "B::b()" << endl; }
    void c(){ cout << "B::c()" << endl; }
    void d(){ cout << "B::d()" << endl; }
};

class C
: public A
, public B
{
public:
    virtual void a(){ cout << "C::a()" << endl; }
    void c(){ cout << "C::c()" << endl; }
    void d(){ cout << "C::d()" << endl; }
};

class D
: public C
{
public:
    void c() {  cout << "D::c()" << endl;   }
};

int main()
{
    cout << "sizeof(C):" << sizeof(C) << endl;
    C c;
    c.a();
    //c.b();//
    c.c();
    c.d();
    cout << endl;

    A * pa = &c;
    pa->a();//C::a()
    pa->b();//A::b()
    pa->c();//C::c()  //通过A类型的指针调用c函数时，表现动态联编
    //pa->d();//error编译时只能看A类型中有几个函数

    cout << endl;
    B * pb = &c;
    pb->a();//C::a()
    pb->b();//B::b()
    pb->c();//B::c() //通过B类型的指针调用c函数时，表现静态联编
    pb->d();//B::d()
    cout << endl;

    C * pc = &c;
    pc->a();//C::a()
    //pc->b();//成员名访问冲突的二义性
    pc->c();//C::c()  走虚函数的机制, 表现动态联编
    pc->d();//C::d()
    cout << endl;
    
    D d;
    pc = &d;
    pc->c();// D::c()   走虚函数的机制

    return 0;
}

